#ifndef     __CAN_FRAME_H
#define     __CAN_FRAME_H

#include <stdint.h>

namespace conn {

struct CANFrame {

    // [31:21] STD_ID [2] IDE 
    // [31:3] EXT_ID [2] IDE
    uint32_t rir; 
    uint8_t len;
    uint8_t buf[8];

    inline uint32_t std_id() const {
        return rir >> 21;
    }

    inline uint32_t ext_id() const {
        return rir >> 3;
    }

    inline bool is_ext() const {
        return (rir & 0x04) != 0;
    }

    inline uint8_t frame_id() const {
        return ((rir >> 3) >> 24) & 0x0F;
    }

    inline bool is_complete() const {
        return ((rir >> 3) >> 28) != 0;
    }

    inline uint8_t src() const {
        return ((rir >> 3) >> 20) & 0x0F;
    }

    inline uint8_t dest() const {
        return ((rir >> 3) >> 16) & 0x0F;
    }
};

}

#endif
